﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class sqlTableEdit : System.Web.UI.Page
{
    public string dbName = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        dbName = Request.QueryString["dbname"];
        if (dbName == "")
        {
            iData.mysqlDataAcess worker = new iData.mysqlDataAcess();
            dbName = worker.dbSetting.database;
        }
        if (!IsPostBack)
        {
            string tblName = Request["tblName"];
            loadData(tblName);
        }

    }


    private void loadData(string tblname)
    {

        string sql = @"select TABLE_COMMENT as tbltitle,TABLE_NAME as tblname from information_schema.TABLES
where table_schema='chromosome_db' and TABLE_NAME='appDataPort'";
        iData.mysqlDataAcess worker = new iData.mysqlDataAcess();
        sql = sql.Replace("appDataPort", tblname);
     
        sql = sql.Replace("chromosome_db", dbName);
       
       
        string tblTitle = worker.ExecuteScalar(sql);

        lblTableName.Text = tblname;
        txtTblName.Text = tblname;
        if (tblTitle != "")
        {

            txtTblTitle.Text = tblTitle;
        }
    }

    private void setTableMemo(string tblname, string memo)
    {

        iData.mysqlDataAcess worker = new iData.mysqlDataAcess();


        string sql = "ALTER TABLE "+dbName+".taskdetail COMMENT='" + memo + "'";
        sql = sql.Replace("taskdetail", tblname);
        //Response.Write(sql);Response.End();
        worker.ExecuteNonQuery(sql);

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string tblTitle = txtTblTitle.Text;
        string tblName = txtTblName.Text;
        setTableMemo(tblName, tblTitle);
        LIB.JsWrite.alertAndCloseUpdateParent("修改成功");
    }
}